import * as types from '../mutation-types'

const mutations = {
  // 屏幕类型
  [types.SET_IS_PHONE](state, payload) {
    state.isPhone = payload
  },
  // 添加到购物车
  [types.ADD_TO_CART](state, payload) {
    const cart = JSON.parse(JSON.stringify(state.cart))
    cart.push(payload)
    state.cart = cart
  },
  // 彩票种类
  [types.SET_LOTTERY_TYPE](state, payload) {
    state.lotteryType = payload
  },
  // 当玩法名称
  [types.SET_CURRENT_MAIN_TAB](state, payload) {
    state.currentMainTab = payload
  },
  // 当前子玩法名称
  [types.SET_CURRENT_TAB](state, payload) {
    state.currentTab = payload
  },
  // 当前玩法对应显示的组件
  [types.SET_CURRENT_COMPONENT](state, payload) {
    state.currentComponent = payload
  },
  // 当前彩票期号
  [types.SET_CURRENT_LOTTERY_DATE_NO](state, payload) {
    state.lotteryDateNo = payload
  },
  // 当前玩法对应的id
  [types.SET_CURRENT_SUB_ID](state, payload) {
    state.currentSubId = payload
  },
  // 彩票单价
  [types.SET_UNIT_PRICE](state, payload) {
    state.unitPrice = payload
  },
  // 单价单位
  [types.SET_UNIT_RATE](state, payload) {
    state.unit = payload
  },
  // 单笔金额 
  [types.SET_SINGLE_AMOUNT](state, payload) {
    state.singleAmount = payload
  },
  // 总金额
  [types.SET_TOTAL_AMOUNT](state, payload) {
    state.totalAmount = payload
  },
  // 返点设置
  [types.SET_REFUND_RATE](state, payload) {
    state.refundRate = payload
  },
  // 彩票数量
  [types.SET_BUYING_QUANTITY](state, payload) {
    state.buyingQuantity = payload
  },
  // 彩票号码信息
  [types.SET_SELECTED_NUMBERS](state, payload) {
    state.selectedNumbers = payload
  },
  // 主导航CUrrentID
  [types.SET_MAIN_TAB_ID](state, payload) {
    state.mainTabCurrendId = payload
  },
  // 二级页面导航条current tab
  [types.SET_SUB_TAB](state, payload) {
    state.subTabCurrentTab = payload
  },
  // 保存彩票球的选中信息
  [types.SET_BALL_SELECTION_STATE](state, payload) {
    state.ballSelectionState = JSON.parse(JSON.stringify(payload))
  },
  // 保存和值位置
  [types.SET_NUMBER_POSITION](state, payload) {
    state.numberPosition = payload
  },
  // 遗漏 缺失
  [types.SET_PARAMETER_TYPE](state, payload) {
    state.parameterType = payload
  },

  // 设置当前页面彩票球状态
  [types.SET_CURRENT_LOTTERY_STATE](state, payload) {
    let lotteryId = state.lotteryType.id 
    let mainTabId = state.currentMainTab.id
    let subTabId = state.currentTab.id
    state.lotteryOptionsData[lotteryId][mainTabId][subTabId].data = payload
  },
  
  // 改变登陆状态
  [types.SET_LOGIN_STATE](state, payload) {
    state.user.isLogin = payload 
  },
  // 设置冷门遗漏activeIndex 
  [types.SET_RADIO_SELECTOR_INDEX](state, payload) {
    state.activeRadioSelectorIndex = payload
  },
  
  // 设置选择的时间 
  [types.SET_SELECTED_TIME](state, payload) {
    state.selectedTime = payload 
  },

  // 删除未付款算订单
  [types.SET_DELETE_ORDER](state, payload) {
    let order = state.cart 
    order.splice(payload, 1)
  },
  // clear cart 
  [types.CLEAR_CART](state, payload) {
    state.cart  = []
  },
  // 清空当前彩票状态 
  [types.CLEAR_STATE](state, payload) {
    let lotteryId = state.lotteryType.id 
    let mainTabId = state.currentMainTab.id
    let subTabId = state.currentTab.id
    if (lotteryId && mainTabId && subTabId) {

      let lotteryState = state.lotteryOptionsData[lotteryId][mainTabId][subTabId].data
      lotteryState && lotteryState.forEach(item => {
        item.numbers.forEach(number => {
          number.selected = false
        })
      })
    }
  },
  // 手机
  [types.SET_SHOW_SIDE_SLIDER](state, payload) {
    state.showSideSlider = payload
  },
  [types.SET_SHOW_SIDE_PANEL](state, payload) {
    state.showSidePanel = payload
  }
}

export default mutations